// import { from } from 'core-js/core/array'
import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home/index'
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    children:[
      {
        path: 'index',
        component: () => import('../views/index.vue'),
        meta:{
          thumb:['首页']
        }
      },
      {
        path: 'director-list',
        component: () => import('../views/director/DirectorList.vue'),
        meta:{
          thumb:['导员管理','导员列表']
        }
      },
      {
        path: 'director-add',
        component: () => import('../views/director/DirectorAdd.vue'),
        meta:{
          thumb:['导员管理','新增导员']
        }
      },
      {
        path: 'actor-list',
        component: () => import('../views/actor/ActorList.vue'),
        meta:{
          thumb:['演员管理','演员列表']
        }
      },
      {
        path: 'actor-add',
        component: () => import('../views/actor/ActorAdd.vue'),
        meta:{
          thumb:['演员管理','新增演员']
        }
      },
      {
        path: 'movie-list',
        component: () => import('../views/movies/MovieList.vue'),
        meta:{
          thumb:['电影管理','电影列表']
        }
      },
      {
        path: 'movie-add',
        component: () => import('../views/movies/MovieAdd.vue'),
        meta:{
          thumb:['电影管理','新增电影']
        }
      },
      {
        path: 'movie-update/:id',
        component: () => import('../views/movies/MovieUpdate.vue'),
        meta:{
          thumb:['电影管理','修改电影']
        }
      },
      {
        path: 'cinema-list',
        component: () => import('../views/cinema/CinemaList.vue'),
        meta:{
          thumb:['电影院管理','电影院列表']
        }
      },
      {
        path: 'cinema-add',
        component: () => import('../views/cinema/CinemaAdd.vue'),
        meta:{
          thumb:['电影院管理','新增电影院']
        }
      },
      {
        path: 'cinema-room-list/:cinemaId',
        component: () => import('../views/cinema/CinemaRoomList.vue'),
        meta:{
          thumb:['电影院管理','电影院列表','放映厅列表']
        }
      },
      {
        path: 'showingon-plan-add/:roomId',
        component: () => import('../views/cinema/ShowingonPlanAdd.vue'),
        meta:{
          thumb:['电影院管理','电影院列表','放映厅列表','新增排片计划']
        }
      },
      {
        path: 'showingon-plan-list/:roomId',
        component: () => import('../views/cinema/ShowingonPlanList.vue'),
        meta:{
          thumb:['电影院管理','电影院列表','放映厅列表','排片计划列表']
        }
      },
    ]
  },
  {
    path: '/user/login',
    name:'login',
    component: () => import('../views/user/Login.vue'),
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// 添加全局前置守卫
import store from '@/store'
router.beforeEach((to, from, next) => {
  console.log(to)
  if (to.path == '/user/login' || store.state.user) {
    next()  // 继续下一步
  } else {
    router.push('/user/login')
  }
})
export default router
